﻿function SaveContact() {
    var pData = { Name: $("#txtName").val(), Phone: $("#txtPhone").val(), Message: $("#txtMessage").val(), Email: $("#txtEmail").val() };
    //var pData = $.string.Format("CustomerName={0}&Phone={1}&Address={2}&Email={3}", $("#txtName").val(), $("#txtPhone").val(), $("#txtAddress").val(), $("#txtEmail").val()) + "}";
    // var pData = { CustomerName=$("#txtName").val(), Phone: $("#txtPhone").val(), Address: $("#txtAddress").val(), Email: $("#txtEmail").val() };
    if (!validator.CheckValidity()) {
        return false;
    }
    $.ajax({
        url: 'Service/ContactService.asmx/SaveContact',
        type: 'POST',
        data: pData,
        cache: false,
        // contentType: "application/json; charset=utf-8",
        // dataType: "json",
        success: function (data, textStatus, jqXHR) {
            data = $(data).find("string").text();
            var mas = eval("(" + data + ")");
            if (mas.IsSuccessfull == true) {
                alert('Thông tin đã được gi nhận');
                $("#txtName").val("");
                $("#txtPhone").val("");
                $("#txtEmail").val("");
                $("#txtMessage").val("");
            }
            //overlay.Hide();
        },
        beforeSend: function (jqXHR, settings) {
            //
            // overlay.Show();
            $(".question").hide();

        },
        error: function (jqXHR, textStatus, errorThrown) {
            //overlay.Hide();
        },
        complete: function (XMLHttpRequest, textStatus) {
            //overlay.Hide();
        }
    });
}
var validator = null;
$(document).ready(function () {
    validator = new CValidator();
    validator.Init("form");
});